from django.shortcuts import render

# Create your views here.
from django.views import View
from .models import GoodsCategory,GoodsChannel,Content,ContentCategory
from .utils import goodscat
'''
data = {
'组别':{
        '一级分类':[{‘id’:id,'name':'手机','url':'链接'}，{'id':id,'name':'数码','url':'链接'}],
        '二级分类':[
        'id':id,
        'name':'手机通讯',
        '三级分类':{'id':id,'name':''}]
        }
'''
class ContentView(View):

    def get(self,request):
          # 三级数据里的sub_cats是cat2_model的一个属性
        # # content_qs = ContentCategory.objects.all().filter(statu=True).older_by('sequence')

        # contcate = ContentCategory.objects.all()   # 先建一个商品类对象
        # content = []
        # for content_model in contcate:
        #     cont = content_model.content_set.filter(status=True).order_by('sequence')
        #     cont_dirt = {content_model.key:cont}
        #     content.append(cont_dirt)
        # context = {
        #     'categories': categories,
        #     'content':content
        # }

        contcate = ContentCategory.objects.all()  # 先建一个商品类对象
        contents = {}
        for cat in contcate:
            cont = cat.content_set.filter(status=True).order_by('sequence')
            contents[cat.key] = cont
        context = {
            'categories': goodscat(),
            'contents': contents,
        }
        return render(request, 'index.html', context)